package enemy.states;

import java.util.ArrayList;
import java.util.List;

import player.Player;

import enemy.Enemy;
import enemy.actions.Action;
import game.Level;

public class Patrol extends State {

	private Enemy enemy;

	private List<Action> actions;
	private int action;

	public Patrol(Enemy enemy) {
		this.enemy = enemy;
		actions = new ArrayList<Action>();
		this.action = 0;
	}

	public void addAction(Action action) {
		actions.add(action);
	}

	@Override
	public void doAction(Level level) {
		//check for player sightings
		
		Player p;
		if((p = level.canSight(enemy)) != null){
			//return;
			enemy.setSighting(p);
		}
		
		//use the level

		// haven't seen enemy so reduce sighting
		if(enemy.getSightedness() > 0f){
			enemy.setSightedness(enemy.getSightedness() - 0.02f);
			if(enemy.getSightedness()  < 0f){
				enemy.setSightedness(0f);
			}
		}

		//if not:
		Action current = actions.get(action);
		if(current.execute(enemy)) {
			this.action++;
			if(action == actions.size()) {
				action = 0;
			}
		}

		

		//else keep going

	}

}
